import Vue from 'vue';
import Router from 'vue-router';

// 按需（懒）加载（vue实现）      @ is an alias to /src
const Layout = () => import('@/views/layouts/layout.vue');// 布局组件
const Login = () => import('@/views/auth/index.vue');// 登录
const Main = () => import('@/views/index/main.vue');// 首页
const Operate = () => import('@/views/user/operate.vue');// 管理人员
const Food = () => import('@/views/food/index.vue');// 菜品
const Shop = () => import('@/views/food/shop.vue');// 店铺
const Error404 = () => import('@/views/page/404.vue');//404

Vue.use(Router);
//设置不需要权限的公共页面
//login 登录成功后不能在访问该页面
export const constantRouterMap= [
    {path: '/login', name: 'Login',component: Login, meta: {title: '登录', login:true}},
    {
        path: '/', component: Layout, redirect: '/main',
        children:[
            {path: '/main', name: 'Main', component: Main,meta: {title:'系统首页',show:true,'icon':'fa fa-home'}},
            {path: '/error/404', name: 'Error404', component: Error404, meta: {title:'404',show:false}},
        ],
    },

];
//实例化vue的时候只挂载constantRouter
export default new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: constantRouterMap
});
//异步挂载的路由
//动态需要根据权限加载的路由表
//access：权限ID，show：菜单是否展示，title:页面title,icon:菜单图标
export const asyncRouterMap = [
    {
        path: '/operate',
        component: Layout,
        children:[
            {path: '/shop',     name: 'Shop',       component: Shop,       meta: {title:'店铺管理',show:true,icon:'fa fa-shopping-cart'}},
            {path: '/food',     name: 'Food',       component: Food,       meta: {title:'菜品管理',show:true,icon:'fa fa-beer'}},
            {path: '/operate',  name: 'Operate',    component: Operate,    meta: {title:'管理人员',show:true,icon:'fa fa-user-o'}},
        ],
    },
    { path: '*',redirect: '/error/404',meta: {show:false},}
];